<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page session="false"%>
<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>admin</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
        
        <link href="<c:url value="/resources/css/style.css" />" rel="stylesheet" type="text/css" />
        <link href="<c:url value="/resources/jqueryui/1.8/themes/ui-lightness/jquery-ui-1.8.16.custom.css" />" rel="stylesheet" type="text/css" />

        <script src="<c:url value="/resources/jquery/jquery.js" />"></script>
        <script src="<c:url value="/resources/jqueryui/1.8/jquery-ui-1.8.16.custom.min.js" />"></script>
        <script src="<c:url value="/resources/jqueryui/1.8/jquery.ui.datepicker-zh-CN.js" />"></script>
        <script src="<c:url value="/resources/jquery/plugin/cookie/jquery.cookie.js" />"></script>
        <script src="<c:url value="/resources/scripts/html5.js" />"></script>
        
        <script src="<c:url value="/resources/scripts/regionUtil.js" />"></script>
        <script src="<c:url value="/categoryUtil" />"></script>
        <style>
        </style>
    </head>
    <body>
        <table class="table-list-style">
            <caption style="text-align:left">
            	<input type="hidden" id="parentId" value="${parentId}" />
            	<span>分类：</span>
            	<span id="parentCategoryListLinks"></span>
            	<a id="btnAddNewCategory" style="float: right;" href="<c:url value="/admin/category/update?pid=" />">添加新分类</a>
            </caption>
            <thead align="left">
                <tr>
                    <th align="left"><input type="checkbox" id="checkboxSelectAll" /></th>
                    <th align="left">编号</th>
                    <th align="left">名称</th>
                    <th align="left">描述</th>
                    <th align="left">查看子类别</th>
                    <th align="left">查看属性</th>
                </tr>
            </thead>
            <tbody>
            
            </tbody>
            
        </table>
        <a id="btnDelCategory" href="javascript:void(0);">删除选中</a>
    </body>
</html>

<script><!--
var msg = '${message}';
var pid = '${parentId}';
var categoryListUrl = '';
var categoryUpdateUrl = '';
var categoryAttrListUrl = '<c:url value="/admin/category/attrList?id=" />';
$(document).ready(function(){
	categoryListUrl = '<c:url value="/admin/category/list?id=" />';
	categoryUpdateUrl = $('#btnAddNewCategory').attr('href');
	$('#checkboxSelectAll').click(function(){
		if($(this).attr('checked')){
			$('table tbody input:checkbox').prop('checked', 'checked');
		}
		else{
			$('table tbody input:checkbox').prop('checked', '');
		}
	});
    viewSubCategories = function(pid){
    	//$('#btnGotoParentCategoryList').attr('href', categoryListUrl + pid);
    	$('#btnAddNewCategory').attr('href', categoryUpdateUrl + pid);
    	$('table.table-list-style tbody').html('');
    	$('#parentCategoryListLinks').html('');
    	$('#parentCategoryListLinks').prepend('<a href="' + categoryListUrl + pid + '">' + CategoryUtil.getItem(pid).name + '</a>');
    	var pc = CategoryUtil.getParent(pid);
    	while(pc!=null){
    		$('#parentCategoryListLinks').prepend('<a href="' + categoryListUrl + pc.id + '">' + pc.name + '</a>');
    		pc = CategoryUtil.getParent(pc.id);
    	}
    	//$('#parentCategoryListLinks').html('<a href="' + categoryListUrl + );
	    var subRegions = CategoryUtil.getSub(pid);
	    if(subRegions!=null){
	    	var html = '';
	    	for (var id in subRegions){
	    		html += '<tr><td><input type="checkbox" value="' + id + '" /></td><td>'
	    		html += id + '</td><td>';
	    		html += subRegions[id].name + '</td><td>';
	    		html += subRegions[id].description + '</td><td>';
	    		html += '<a href="javascript: viewSubCategories(\'' + id + '\');">查看子分类</a></td><td>';
	    		html += '<a href="<c:url value="/admin/category/attrList?id=" />' + id +'">查看属性</a></td></tr>';
	    	}
	    	
	    	$(html).appendTo($('table.table-list-style tbody'));
	    }
	    $('a').button();
    };
	
	viewSubCategories(pid); 
	
	function deleteCategories(){
		var categoryDelUrl = '<c:url value="/admin/category/delete?ids=" />';
		var ids = '';
		$('table tbody input:checked').each(function(){
			ids += $(this).val() + ';';
		});
		if(ids!=''&&confirm('确认要删除选中的分类吗?')){
			document.location.href = categoryDelUrl + ids;
		} 
	};
	
	$('#btnDelCategory').click(function(){
		deleteCategories();
	});
});
--></script>
